package core.ui.demo;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Demo extends Application
{
	public static void main(String[] args)
	{
		launch(args);  
	}

	private void initView(final Stage primaryStage)
	{
		final ComboBox<String> comboBox = new ComboBox<>();
		comboBox.getItems().addAll(new String[]{"Demo1","Demo2"});
		comboBox.setValue("Demo1");
		
		Button button = new Button("跳转");
		button.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent arg0) {
				try {
					switch (comboBox.getValue())
					{
						case "Demo1":
							new Demo1().start(primaryStage);
							break; 
						case "Demo2":
							new Demo2().start(primaryStage);
							break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
//		button.setOnAction((ActionEvent ae)
//		{ 
//			try
//			{
//				switch (comboBox.getValue())
//				{
//					case "Demo1":
//						new Demo1().start(primaryStage);
//						break; 
//					case "Demo2":
//						new Demo2().start(primaryStage);
//						break;
//				}
//			}catch(Exception e)
//			{
//				
//			}
//		});
		
		HBox box = new HBox(comboBox,button);
		box.setPadding(new Insets(20));
		box.setSpacing(10);
		
		Scene scene = new Scene(box,400,200);
		primaryStage.setScene(scene);
	}
	public void start(Stage primaryStage) throws Exception
	{
		initView(primaryStage);
		primaryStage.show();	
	}
}
